<include file="Public:header" />
<div style="boder:1px solid #ccc;margin:10px 10px 0px 10px;">
    <div style="border:1px solid #ccc;height:40px;padding:0 0 0 20px;line-height:40px;">
           本站图片水印配置
    </div>
    <form action="{:U('WebsiteConfigManage/watermark')}" method="get">
    <div style="border:1px solid #ccc;height:auto;padding:10px 0px 10px 13px;margin-top:5px;"> 
                    <select name="column_id">
					    <option value="0">请选择栏目</option>
                        <foreach name="columnName" item="val">
                        <option value="{$val.id}" <if condition="$val.id eq $column_id">selected</if> >{$val.column_name}</option>
                        </foreach>
                    </select>
                    <input type="submit" name="config" value="配置" />
    </div>
    </form>
    <if condition="$watermarkConfig neq null">
    <form action="{:U('WebsiteConfigManage/watermark')}" method='post' enctype="multipart/form-data" onsubmit="return checkForm()">
    <div style="border:1px solid #ccc;height:auto;padding:5px 11px 5px 11px;margin-top:5px;"> 
    <table width="100%">
           <tr>
                <td colspan="2">此设置将在开启独立上传，且上传图片时，有效！</td>
           </tr>
           <tr>
               <td width="150" align="right" style="border:1px solid #ccc">{$watermarkConfig[0]['config_name']}：</td>
               <td style="border:1px solid #ccc">
                   <input type="hidden" name="id[0]" value="{$watermarkConfig[0]['id']}" />
                   &nbsp;<input id="radio_1" type="radio" name="config_info[0]" value="1" 
     </if>
     <if condition="$watermarkConfig[0]['config_info'] eq '1'">checked</if>
     <if condition="$watermarkConfig neq null">/> 是
                   <input id="radio_2" type="radio" name="config_info[0]" value="0"
     </if>
     <if condition="$watermarkConfig[0]['config_info'] eq '0'">checked</if>
     <if condition="$watermarkConfig neq null">/> 否
               </td>
           </tr>
     </if>
     <if condition="$watermarkConfig[0]['config_info'] eq '1'">
           <tr>
               <td align="right" style="border:1px solid #ccc">{$watermarkConfig[1]['config_name']}：</td>
               <td style="border:1px solid #ccc">
                   <input type="hidden" name="id[1]" value="{$watermarkConfig[1]['id']}" />
                   <input id="watermarkSize" type="text" name="config_info[1]" value="{$watermarkConfig[1]['config_info']}" />
                   <span id="errorSize">请使用<span style="color:red">*x*</span>这种格式，*(长)x(为小写字母x)*(宽)</span>
               </td>
           </tr>
           <tr>
               <td align="right" style="border:1px solid #ccc">{$watermarkConfig[3]['config_name']}：</td>
               <td style="border:1px solid #ccc">
                   <input type="hidden" name="id[3]" value="{$watermarkConfig[3]['id']}" />
                   <input id="watermarkAlpha" type="text" name="config_info[3]" value="{$watermarkConfig[3]['config_info']}" /> % <span id="errorAlpha">水印图片的透明度，值为0 - 100，依次递增！</span>
               </td>
           </tr>
           <tr>
               <td align="right" style="border:1px solid #ccc">{$watermarkConfig[2]['config_name']}：</td>
               <td style="border:1px solid #ccc">
                   <input type="hidden" name="id[2]" value="{$watermarkConfig[2]['id']}" />
                   <input id="fileUpload" type="file" name="Image" value="" /> <span id="errorFile"></span>
               </td>
           </tr>
           
    </if>
    <if condition="$watermarkConfig[2]['config_info'] neq ''">
           <tr>
               <td></td>
               <td>
                   <img id="watermarkImg" src="__ROOT__/Data/Admin/Uploads/{$watermarkConfig[2]['config_info']}"></img>
               </td>
           </tr>
    </if>
    <if condition="$watermarkConfig neq null">
    </table>
    </div>
    <div style="border:1px solid #ccc;margin:5px 0px 5px 0px;padding:5px 0px 5px 13px;">
            <input type="hidden" name="column_id" value="{$column_id}" />
            <input type="submit" name="save" value="保存配置" />
            <input type="reset" value="重置" />
    </div>
    </form>
    </if>
</div>
  </body>
  <script type="text/javascript">
          //alert(document.getElementById("watermarkImg"));
          function checkForm(){
              //1.图片的长宽小于或等于零时不允许提交
              //水印透明度小于等于零的时候不允许提交
              var watermarkSize;   //水印大小对象
              var waterMarkAlpha;  //水印透明度对象
              var size;            //水印大小的值
              var alpha;           //水印透明度的值
              var position;        //获取水印大小的截取位置（获得长宽的值） 
              var width;           //水印的宽值
              var length;          //水印的长值
              var errorSize  = document.getElementById("errorSize");
              var errorAlpha = document.getElementById("errorAlpha");
              var fileUpload = document.getElementById("fileUpload");
              var errorFile  = document.getElementById("errorFile");
              var radio_1    = document.getElementById("radio_1").checked;
              var radio_2    = document.getElementById("radio_2").checked;
              var watermarkImg = document.getElementById("watermarkImg");

              watermarkSize = document.getElementById("watermarkSize");
              size          = watermarkSize.value;
              waterMarkAlpha= document.getElementById("watermarkAlpha");
              alpha         = waterMarkAlpha.value;
              position      = size.indexOf("x");
              length        = size.substr(0,position);
              width         = size.substr(position+1,size.length);
              file          = fileUpload.value;
              
              if(radio_1 == true){
                    if(length <= 0 || width <= 0 ){
                            errorSize.innerHTML = "<span style='color:red'>水印图片的长或宽不能小于或等于零！</span>";
                            return false;
                    }else{
                            errorSize.innerHTML = "<span style='color:green'>格式正确！</span>";
                    }
                    if(alpha <= 0 || alpha >= 100){
                            errorAlpha.innerHTML = "<span style='color:red'>水印图片的的透明度不能小于或等于零或者大于等于一百！</span>";
                            return false;
                    }else{
                            errorAlpha.innerHTML = "<span style='color:green'>格式正确！</span>";
                    }
                    if(file == '' && watermarkImg == null){
                            errorFile.innerHTML = "<span style='color:red'>请选择一张水印图片！</span>";
                            return false;
                    }else{
                            errorFile.innerHTML = "<span style='color:green'>水印图片已选择！</span>";
                    }
                    if(length > 0 && width > 0 && alpha >0 && alpha <= 100){
                            return true;
                    }else{
                            return false;
                    }
              }else if(radio_2 == true){
                      return true;
              }
          }
  </script>
</html>
